#include <jni.h>
#include <string>


extern "C"
JNIEXPORT jbyte JNICALL
Java_com_zjk_crc8_CrcUtils_Crc8(JNIEnv *env, jclass clazz, jbyteArray prt) {
    uint8_t crc = 0;
    jsize length = env->GetArrayLength(prt);
    jbyte *jbyte = env->GetByteArrayElements(prt, nullptr);


    while (length--) {
        crc ^= *jbyte++;
        for (uint8_t i = 0; i < 8; i++) {
            if (crc & 0x01) {
                crc = (crc >> 1) ^ 0x8C;
            } else {
                crc >>= 1;
            }
        }
    }
    return crc;
}